home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 6 / MacAddict_006_1997_02.iso / Software Updates / MacsBug 6.5.3 / Building dcmds / C Samples / Echo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  2.6 KB  |  124 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Echo.c
  3.  
  4.     Contains:    A sample dcmd which echos all command line parameters.
  5.  
  6.     Written by:    JM3 = Jim Murphy
  7.  
  8.     Copyright:    © 1988, 1994, 1996 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <4>   25-Jan-96    JM3        Added sample build commands.
  13.          <3>   10-Dec-94    JM3        Updated for new format 3 dcmd requirements.
  14.          <2>    1-Sep-94    JM3        Included string.h so we build with no warnings with -r.
  15.  
  16.     The following MPW commands will build the dcmd and copy it to the "Debugger Prefs" file
  17.     in the System folder. The dcmd's name in MacsBug will be the name of the file built by
  18.     the Linker.
  19.  
  20.     C Echo.c
  21.     Link -o Echo -sg Main=STDCLIB,STDIO,SANELIB dcmdGlue.a.o Echo.c.o"    ∂
  22.         "{Libraries}Runtime.o" "{CLibraries}StdCLib.o"
  23.     BuildDcmd Echo 192 -format3
  24.     Echo 'include "Echo";'    |    Rez -a -o "{SystemFolder}Debugger Prefs"
  25.  
  26. */
  27.  
  28.  
  29. #include <Memory.h>
  30. #include <Types.h>
  31. #include <string.h>
  32.  
  33. #include "dcmd.h"
  34.  
  35. void NumberToHex (long number, Str255 hex)
  36. {
  37.  
  38.     Str255    digits = "0123456789ABCDEF";
  39.     int        n;
  40.  
  41.     strcpy (hex, &".00000000");
  42.     hex[0] = 8;
  43.     for (n = 8; n >= 1; n--)
  44.     {
  45.         hex[n] = digits[number % 16];
  46.         number = number / 16;
  47.     }
  48.  
  49. } // NumberToHex
  50.  
  51.  
  52. pascal void CommandEntry (dcmdBlock* paramPtr)
  53. {
  54.  
  55.     short    pos, ch;
  56.     long    value;
  57.     Boolean    ok;
  58.     Str255    str;
  59.  
  60.     static const char usageStr[] = "\p[params...]";
  61.  
  62.     switch (paramPtr->request)
  63.     {
  64.         case dcmdInit:
  65.             break;
  66.  
  67.         case dcmdHelp:
  68.             dcmdDrawLine("\pEcho the command line parameters");
  69.             break;
  70.  
  71.         case dcmdGetInfo:
  72.             * (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03008000; // version 3.0 final
  73.             BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
  74.             break;
  75.  
  76.         case dcmdDoIt:
  77.             do
  78.             {
  79.                 // Save the position so we can rewind if we get an error
  80.             
  81.                 pos = dcmdGetPosition ();
  82.                 ch  = dcmdPeekAtNextChar ();
  83.  
  84.                 if (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')))
  85.                 {
  86.                     // Get the parameter as a text string
  87.  
  88.                     ch = dcmdGetNextParameter (str);
  89.                     dcmdDrawLine (str);
  90.  
  91.                 }
  92.                 else
  93.                 {
  94.                     // Get the parameter as a 32 bit value
  95.  
  96.                     ch = dcmdGetNextExpression (&value, &ok);
  97.  
  98.                     if (ok)
  99.                     {    
  100.                         // The expression was parsed correctly
  101.  
  102.                         NumberToHex (value, str);
  103.                         dcmdDrawLine (str);
  104.  
  105.                     }
  106.                     else
  107.                     {    
  108.                         // The expression contained an error. Get it as a string
  109.  
  110.                         dcmdSetPosition (pos);
  111.                         ch = dcmdGetNextParameter (str);
  112.                         dcmdDrawLine (str);
  113.                     }
  114.                 }
  115.             } while (ch != '\n');
  116.                 break;
  117.  
  118.         // Version 3 and newer dcmds must quietly ignore requests we don't recognize.
  119.     
  120.         default:
  121.             break;
  122.     }
  123. } // CommandEntry
  124.